home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas_0593.zip / ENCRYPT.TXT < prev    next >
Text File  |  1993-05-30  |  3KB  |  84 lines

  1. ─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 362 of 384                                                               
  3. From : Steve Connet                        1:300/15.0           26 May 93  10:43 
  4. To   : Rob Perelman                                                              
  5. Subj : Encryption Alg.                                                        
  6. ────────────────────────────────────────────────────────────────────────────────
  7. Hello Rob, 
  8.  
  9. RP> >  Password[i] := Char(Ord(Password[i]) XOR i) 
  10.  
  11. RP>Can you tell me what XOR does? 
  12.  
  13.  
  14. XOR stands for Exclusive Or.  Here is the Truth Table for XOR: 
  15.  
  16. 0 xor 0 = 0 
  17. 0 xor 1 = 1 
  18. 1 xor 0 = 1 
  19. 1 xor 1 = 0 
  20.  
  21. Here is how it works: 
  22.  
  23. Say I have the string "ABC".  Here is a table showing the letters, their 
  24. ascii value, and their binary value.  (We will work with the binary 
  25. value). 
  26.  
  27. LETTER  ASCII  BINARY 
  28. ------  -----  --------- 
  29.   A      65    0100 0001 
  30.   B      66    0100 0010 
  31.   C      67    0100 0011 
  32.  
  33. Here is the encryption snippet again: 
  34.  
  35.   For i := 1 to ord(Password[0]) do 
  36.     Password[i] := Char(Ord(Password[i]) XOR i) 
  37.  
  38. If you follow this snippet, you'll see that the first element of the 
  39. string is being xored by the position of the element (ie. XOR i). 
  40.  
  41. For example, 'ABC' would be xored like this: 
  42.  
  43. A xor 1 
  44. B xor 2 
  45. C xor 3 
  46.  
  47. That way the the right side of the xor is always changing, and thus hard 
  48. to decrypt manually.  If the right side of the xor was, say, always 255, 
  49. every element of the string would be xored by 255 and a hacker could 
  50. figure it out.  If the right side is always changing, it is much harder 
  51. to figure out.  So let's take a look at what happens when we use our 
  52. snippet with the string 'ABC'. 
  53.  
  54. LETTER      ASCII        BINARY (this shows us how it works) 
  55. (A xor 1) = (65 xor 1) = (0100 0001 xor 1) 
  56. (B xor 2) = (66 xor 2) = (0100 0010 xor 2) 
  57. (C xor 3) = (67 xor 3) = (0100 0011 xor 3) 
  58.  
  59. Remember the truth table concerning XOR above?  Let's look at the binary 
  60. equivalent of our 'ABC' string. 
  61.  
  62. A                B               C                Truth table 
  63. -------------    -------------   -------------    -------------- 
  64. 0100 0001 xor    0100 0010 xor   0100 0011 xor    0 xor 0 = 0 
  65. 0000 0001        0000 0010       0000 0011        0 xor 1 = 1 
  66. =========        =========       =========        1 xor 0 = 1 
  67. 0100 0000        0100 0000       0100 0000        1 xor 1 = 0 
  68.  
  69. Using our snippet, the resulting value for EACH element of the string 
  70. 'ABC' is, surprisingly, 0100 0000 (which equals 64 decimal) which is the 
  71. character '@'. 
  72.  
  73. So the resulting value of the string 'ABC' when XORed with our snippet 
  74. is the new string '@@@'. 
  75.  
  76. So 'ABC' encrypted with our snippet becomes '@@@'.  How is it possible 
  77. at all for a hacker to get 'ABC' out of '@@@'???  So you see, our 
  78. snippet works quite well. 
  79.  
  80. To decrypt the string, just send it right back through our snippet.  So 
  81. if you stick '@@@' in our snippet ... 'ABC' will be the resulting value. 
  82.  
  83. Pretty neat eh? 
  84.